﻿Imports DevExpress.XtraGrid.Views.Grid
Imports DevExpress.XtraGrid.Columns
Imports DevExpress.Utils
Imports DevExpress.XtraPrinting
Imports DevExpress.XtraGrid.Menu
Imports DevExpress.Utils.Menu
Imports DevExpress.XtraPrintingLinks
Imports System.Drawing
Imports DevExpress.LookAndFeel
Imports IControl.IControls
Imports DevExpress.XtraGrid.Views.Base
Imports DevExpress.Data.Filtering
Public Class IGridView
    Inherits DevExpress.XtraGrid.Views.Grid.GridView
    Private flagAcc As Boolean = True
    Private flagDropDown As Boolean = True
    Private header As String = ""
    Private footer As String = ""
    Private title As String = ""
    Private fax As String = ""
    Private email As String = ""
    Private address As String = ""
    Private htBatLoi As Hashtable = New Hashtable
    Private isLock As Boolean
    Private components As System.ComponentModel.IContainer
    Public WithEvents PrintableComponentLink2 As DevExpress.XtraPrinting.PrintableComponentLink
    Private printingSystem1 As DevExpress.XtraPrinting.PrintingSystem
    Private ht As Hashtable
    Private selection_Renamed As GridCheckMarksSelection

    ''' <summary>
    ''' cho phép khi nào xổ xuống tự động trên lưới khi enter 
    ''' </summary>
    ''' <param name="b">true - false</param>
    ''' <remarks>Dùng trong tình huống enter từ trên thông tin xuống lưới (để khỏi bị chớp)</remarks>
    Public Sub setFlagDropDown(ByVal b As Boolean)
        Me.flagDropDown = b
    End Sub
    ''' <summary>
    ''' tạo cột checkbox ở đầu của igridview
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub setColumnCheck()
        selection_Renamed = New GridCheckMarksSelection(Me)
        selection_Renamed.CheckMarkColumn.VisibleIndex = 0
    End Sub
    ''' <summary>
    ''' chọn check tất cả checkbox (sau khi chọn setcolumnCheck)
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub SelectAllCheck()
        selection_Renamed.SelectAll()
    End Sub
    ''' <summary>
    ''' bỏ chọn check tất cả checkbox
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub ClearAllSelectCheck()
        selection_Renamed.ClearSelection()
    End Sub
    Public Sub setHeaderFooter(ByVal hd As String, ByVal ad As String)
        Me.header = hd
        Me.address = ad
    End Sub
    ''' <summary>
    ''' set các thông tin cần thiết lên phần in báo cáo nhanh
    ''' </summary>
    ''' <param name="hd">tên công ty của report (phần góc trái)</param>
    ''' <param name="ad">địa chỉ của report (phần góc trái)</param>
    ''' <param name="ps"></param>
    ''' <param name="pcl"></param>
    ''' <remarks></remarks>
    Public Sub setHeaderFooter(ByVal hd As String, ByVal ad As String, ByVal ps As DevExpress.XtraPrinting.PrintingSystem, ByVal pcl As PrintableComponentLink)
        Me.header = hd
        Me.address = ad
        Me.printingSystem1 = ps
        Me.PrintableComponentLink2 = pcl
    End Sub
    ''' <summary>
    ''' set các thông tin cần thiết lên phần in báo cáo nhanh
    ''' </summary>
    ''' <param name="hd"></param>
    ''' <param name="ad"></param>
    ''' <param name="ps"></param>
    ''' <param name="pcl"></param>
    ''' <remarks></remarks>
    Public Sub setHeaderFooter(ByVal hd As String, ByVal ad As String, ByVal tl As String, ByVal ps As DevExpress.XtraPrinting.PrintingSystem, ByVal pcl As PrintableComponentLink)
        Me.header = hd
        Me.address = ad
        Me.printingSystem1 = ps
        Me.PrintableComponentLink2 = pcl
        Me.title = tl
    End Sub
    ''' <summary>
    ''' Set tiêu đề của report in ra từ grid
    ''' </summary>
    ''' <param name="title">tiêu đề của report in ra từ grid (in báo cáo nhanh)</param>
    ''' <remarks></remarks>
    Public Sub setTitle(ByVal title As String)
        Me.title = title
    End Sub
    ''' <summary>
    ''' khóa lại tất cả các row chỉ trừ dòng đang được chọn
    ''' </summary>
    ''' <param name="b"></param>
    ''' <remarks></remarks>
    Public Sub setLock(ByVal b As Boolean)
        Me.isLock = b
    End Sub

    ''' <summary>
    ''' set lại trên lưới trạng thái readonly
    ''' </summary>
    ''' <param name="isTrue"> true thì không cho chỉnh sửa trên lưới - false thì cho </param>
    ''' <remarks></remarks>
    Public Sub setReadonly(ByVal isTrue As Boolean)
        If isTrue Then
            Me.OptionsBehavior.Editable = False
        Else
            Me.OptionsBehavior.Editable = True
        End If

    End Sub
    ''' <summary>
    ''' Lấy giá trị tổng cộng của cột 
    ''' </summary>
    ''' <param name="tên_cột">Tên cột cần lấy giá trị</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function getSummaryColumn(ByVal tên_cột As String) As Decimal
        Return CDec(Me.Columns(tên_cột).SummaryItem.SummaryValue)
    End Function
    ''' <summary>
    ''' cho phép thêm dòng (dòng trống ở cuối của igridview
    ''' </summary>
    ''' <param name="b"></param>
    ''' <remarks></remarks>
    Public Sub setChoPhepThemDong(ByVal b As Boolean)
        If b Then
            Me.OptionsView.NewItemRowPosition = NewItemRowPosition.Bottom
        Else
            Me.OptionsView.NewItemRowPosition = NewItemRowPosition.None
        End If
    End Sub

    Public Sub setMacDinh(ByVal tên_cột As String, ByVal giá_trị As Object)
        ht.Add(tên_cột, giá_trị)
    End Sub
    Public Sub setDisable_EnterMoveNextColumn()
        Me.OptionsNavigation.EnterMoveNextColumn = False
    End Sub
    Public Sub setEnable_EnterMoveNextColumn()
        Me.OptionsNavigation.EnterMoveNextColumn = True
    End Sub
    Public Sub New()
        MyClass.New(Nothing)
        Me.IndicatorWidth = 55
        Me.OptionsNavigation.EnterMoveNextColumn = True
        Me.OptionsBehavior.Editable = True
        Me.OptionsNavigation.AutoFocusNewRow = True
        Me.OptionsView.EnableAppearanceOddRow = True
        Me.Appearance.SelectedRow.BackColor = System.Drawing.Color.RoyalBlue
        Me.Appearance.SelectedRow.BackColor2 = System.Drawing.Color.White
        Me.Appearance.OddRow.BackColor = System.Drawing.Color.LightCyan
        'Me.Appearance.Row.BackColor = System.Drawing.Color.LightBlue
        Me.Appearance.FocusedRow.BackColor = System.Drawing.Color.RoyalBlue
        'Me.GroupFooterShowMode = DevExpress.XtraGrid.Views.Grid.GroupFooterShowMode.VisibleAlways

        ht = New Hashtable
        ' AddHandler Me.MouseDown, AddressOf Me_MouseDown
    End Sub

    Public Sub New(ByVal grid As DevExpress.XtraGrid.GridControl)
        MyBase.New(grid)
        Me.OptionsNavigation.EnterMoveNextColumn = True
        Me.OptionsBehavior.Editable = True
        Me.OptionsNavigation.AutoFocusNewRow = True
        Me.IndicatorWidth = 55
        Me.OptionsView.EnableAppearanceOddRow = True
        Me.Appearance.SelectedRow.BackColor = System.Drawing.Color.RoyalBlue
        Me.Appearance.SelectedRow.BackColor2 = System.Drawing.Color.RoyalBlue
        Me.Appearance.OddRow.BackColor = System.Drawing.Color.LightCyan
        'Me.Appearance.Row.BackColor = System.Drawing.Color.LightBlue
        Me.Appearance.FocusedRow.BackColor = System.Drawing.Color.RoyalBlue
    End Sub

    Protected Overrides ReadOnly Property ViewName() As String
        Get
            Return "MyGridView"
        End Get
    End Property

    Private Sub InitializeComponent()
        CType(Me, System.ComponentModel.ISupportInitialize).BeginInit()
        '
        'IGridView
        '
        Me.Appearance.EvenRow.BackColor = System.Drawing.Color.Red
        Me.Appearance.FocusedCell.BackColor = System.Drawing.Color.Yellow
        Me.Appearance.GroupPanel.BackColor = System.Drawing.Color.Blue
        Me.Appearance.HeaderPanel.BackColor = System.Drawing.Color.Lime
        Me.Appearance.OddRow.BackColor = System.Drawing.Color.LightGreen
        Me.Appearance.OddRow.Options.UseBackColor = True
        Me.OptionsCustomization.AllowColumnMoving = False
        Me.OptionsCustomization.AllowColumnResizing = False
        Me.OptionsCustomization.AllowRowSizing = True
        Me.OptionsView.EnableAppearanceEvenRow = True
        Me.OptionsView.EnableAppearanceOddRow = True
        Me.ViewCaption = "IGridView"
        CType(Me, System.ComponentModel.ISupportInitialize).EndInit()

    End Sub

    Private Sub IGridView_CustomDrawRowIndicator(sender As Object, e As DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs) Handles Me.CustomDrawRowIndicator
        Dim view As GridView = DirectCast(sender, GridView)
        Dim indicatorIcon As Boolean = False
        If e.RowHandle >= 0 Then 'trừ trường hợp -1
            'Check whether the indicator cell belongs to a data row
            If e.Info.IsRowIndicator Then
                e.Info.DisplayText = (e.RowHandle + 1).ToString()
                If Not indicatorIcon Then
                    e.Info.ImageIndex = -1
                End If
            End If
        End If
    End Sub

    Private Sub IGridView_InitNewRow(sender As Object, e As DevExpress.XtraGrid.Views.Grid.InitNewRowEventArgs) Handles Me.InitNewRow
        Dim Item As DictionaryEntry
        For Each Item In ht
            If Me.Columns.Contains(Me.Columns(Item.Key.ToString)) Then
                Me.SetFocusedRowCellValue(Me.FocusedColumn, Item.Value)
            Else
                DevExpress.XtraEditors.XtraMessageBox.Show("Cột '" & Item.Key.ToString & "' không tồn tại, bạn coi lại hàm 'setMacDinhCotAn' ?", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            End If
        Next
    End Sub

    Private Sub IGridView_InvalidRowException(sender As Object, e As DevExpress.XtraGrid.Views.Base.InvalidRowExceptionEventArgs) Handles Me.InvalidRowException
        e.ExceptionMode = DevExpress.XtraEditors.Controls.ExceptionMode.NoAction
    End Sub

    Private Sub IGridView_InvalidValueException(sender As Object, e As DevExpress.XtraEditors.Controls.InvalidValueExceptionEventArgs) Handles Me.InvalidValueException
        e.ExceptionMode = DevExpress.XtraEditors.Controls.ExceptionMode.DisplayError
    End Sub

    Private Sub IGridView_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        If (e.KeyCode = Keys.Enter) Then
            'If (MessageBox.Show("Delete row?", "Confirmation", _
            '  MessageBoxButtons.YesNo) <> DialogResult.Yes) Then Return
            'Dim view As GridView = CType(sender, GridView)
            'view.DeleteRow(view.FocusedRowHandle)
            'MessageBox.Show("enter kìa ;) !")
            Me.setFlagDropDown(True)
            'If (TypeOf Me.ActiveEditor Is IControls.ISearchLookupEdit And IsDBNull(Me.FocusedValue)) Then
            If (TypeOf Me.ActiveEditor Is IControls.ISearchLookupEdit) Then
                DirectCast(Me.ActiveEditor, ISearchLookupEdit).ShowPopup()
                'Me.setFlagDropDown(False)
                'Me.flagAcc = False
                'MessageBox.Show("flagDropDown 2")
            End If
        End If

        If (e.KeyCode = Keys.F12) Then
            'Dim OpenFileDialog1 As OpenFileDialog = New OpenFileDialog()
            'OpenFileDialog1.Filter = "xml files (*.xml)|*.xml"
            'OpenFileDialog1.FilterIndex = 1
            'OpenFileDialog1.RestoreDirectory = True


            'If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
            '    'Me.GridView1.Appearance.RestoreLayoutFromXml(Me.OpenFileDialog1.FileName.ToString)
            '    Me.RestoreLayoutFromXml(OpenFileDialog1.FileName.ToString)
            'End If
            'Me.OptionsLayout.Columns.RemoveOldColumns = False
            Me.OptionsLayout.Columns.StoreAllOptions = True
            Me.OptionsLayout.StoreAllOptions = True
            Me.OptionsLayout.StoreAppearance = True
            Dim SaveFileDialog1 As SaveFileDialog = New SaveFileDialog
            SaveFileDialog1.Filter = "xml files (*.xml)|*.xml"
            SaveFileDialog1.FilterIndex = 1
            SaveFileDialog1.RestoreDirectory = True

            If SaveFileDialog1.ShowDialog() = DialogResult.OK Then
                ' Me.GridView1.Appearance.SaveLayoutToXml(Me.SaveFileDialog1.FileName.ToString)
                Me.SaveLayoutToXml(SaveFileDialog1.FileName.ToString)
            End If
        End If

    End Sub

    Private Sub IGridView_MouseDown(sender As Object, e As MouseEventArgs) Handles Me.MouseDown
        If isLock AndAlso Me.CalcHitInfo(e.Location).InRow Then
            DirectCast(e, DXMouseEventArgs).Handled = True
        End If
        Me.flagDropDown = True
    End Sub


    Private Sub IGridView_PopupMenuShowing(sender As Object, e As DevExpress.XtraGrid.Views.Grid.PopupMenuShowingEventArgs) Handles Me.PopupMenuShowing
        If e.MenuType = GridMenuType.Column Then
            Dim menu As GridViewColumnMenu = e.Menu
            'Dim item As New DevExpress.Utils.Menu.DXMenuItem("MyMenuItem")
            'item.BeginGroup = True
            'menu.Items.Clear()
            If Not menu.Column Is Nothing Then
                menu.Items.Add(CreateCheckItem("In báo cáo nhanh", menu.Column, Nothing))
                'menu.Items.Add(item)
            End If
        End If
    End Sub
    Public Sub inNhanh()
        PrintableComponentLink2.ClearDocument() 'thử
        PrintableComponentLink2.Landscape = True
        Dim leftColumn As String = header.ToUpper & vbCrLf & address.ToUpper
        Dim middleColumn As String = "[Tên Người dùng]"
        '======== footer ======================
        Dim leftColumnFooter As String = "[Trang # / #]"
        Dim rightColumnfooter As String = "[Giờ in][Ngày in]"
        ' Create a PageHeaderFooter object and initializing it with
        ' the link's PageHeaderFooter.
        Dim phf As PageHeaderFooter = TryCast(PrintableComponentLink2.PageHeaderFooter, PageHeaderFooter)
        Dim phfooter As PageHeaderFooter = TryCast(PrintableComponentLink2.PageHeaderFooter, PageHeaderFooter)
        ' Clear the PageHeaderFooter's contents.
        phf.Header.Content.Clear()

        ' Add custom information to the link's header.
        phf.Header.Content.AddRange(New String() {leftColumn, "", Nothing})
        'set title
        AddHandler PrintableComponentLink2.CreateReportHeaderArea, AddressOf PrintableComponentLink2_CreateReportHeaderArea
        phf.Header.LineAlignment = BrickAlignment.Center

        ' Show the document's preview.
        phfooter.Footer.Content.Clear()
        phf.Footer.Content.AddRange(New String() {leftColumnFooter, middleColumn, rightColumnfooter})
        phf.Footer.LineAlignment = BrickAlignment.Center
        PrintableComponentLink2.ShowRibbonPreview(UserLookAndFeel.Default)
    End Sub
    Private Sub PrintableComponentLink2_CreateReportHeaderArea(sender As Object, e As DevExpress.XtraPrinting.CreateAreaEventArgs) Handles PrintableComponentLink2.CreateReportHeaderArea
        Dim brick As DevExpress.XtraPrinting.TextBrick
        brick = e.Graph.DrawString(Me.title.ToUpper, Color.Navy, New RectangleF(0, 0, 500, 40), DevExpress.XtraPrinting.BorderSide.None)
        brick.Font = New Font("Tahoma", 16)
        brick.StringFormat = New DevExpress.XtraPrinting.BrickStringFormat(StringAlignment.Center)
    End Sub
    ' Menu item click handler.
    Public Overridable Sub OnCanMovedItemClick(ByVal sender As Object, ByVal e As EventArgs)
        inNhanh()
    End Sub
    ' The class that stores menu specific information.
    Class MenuColumnInfo
        Public Sub New(ByVal column As GridColumn)
            Me.Column = column
        End Sub
        Public Column As GridColumn
    End Class
    ' Creates a menu item.
    Function CreateCheckItem(ByVal caption As String, ByVal column As GridColumn, ByVal image As Image) As DXMenuItem
        Dim item As DXMenuItem = New DXMenuItem(caption, AddressOf OnCanMovedItemClick)
        item.Tag = New MenuColumnInfo(column)
        Return item
    End Function

    Private Sub IGridView_ShownEditor(sender As Object, e As System.EventArgs) Handles Me.ShownEditor
        Dim view As DevExpress.XtraGrid.Views.Base.ColumnView = CType(sender, DevExpress.XtraGrid.Views.Base.ColumnView)
        Try
            view.ActiveEditor.IsModified = True
        Catch ex As Exception
        End Try
        'setdropdown - tự động dropdown xuống
        'If Me.flagDropDown Then
        'Else
        If TypeOf Me.ActiveEditor Is DevExpress.XtraEditors.SearchLookUpEdit And IsDBNull(Me.FocusedValue) Then
            DirectCast(Me.ActiveEditor, DevExpress.XtraEditors.SearchLookUpEdit).ShowPopup()
            'Me.ShowEditorByMouse()
        End If
        'If (TypeOf Me.ActiveEditor Is IControls.ISearchLookupEdit And IsDBNull(Me.FocusedValue)) Then
        'If (TypeOf Me.ActiveEditor Is IControls.ISearchLookupEdit) Then
        'DirectCast(Me.ActiveEditor, ISearchLookupEdit).ShowPopup()
        'Me.setFlagDropDown(False)
        'If Me.IsClosingEditor Then
        '    DirectCast(Me.ActiveEditor, ISearchLookupEdit).ShowPopup()
        'End If
        'Me.setFlagDropDown(False)
        'End If
        'End If
    End Sub

    Private Sub IGridView_ValidatingEditor(sender As Object, e As DevExpress.XtraEditors.Controls.BaseContainerValidateEditorEventArgs) Handles Me.ValidatingEditor
        Dim stencot As String
        Dim Item As DictionaryEntry
        For Each col As GridColumn In Me.Columns
            stencot = col.FieldName
            For Each Item In htBatLoi
                If Me.FocusedColumn.FieldName = Item.Key And Me.FocusedRowHandle <> -999997 Then
                    'bắt lỗi khi một cột nào đó (giá trị số) bằng giá trị định trước
                    ''kiểm tra dạng số 
                    'If Item.Value.ToString.Contains(">") Or Item.Value.ToString.Contains(">") Or Item.Value.ToString.Contains("=") Then
                    '    ' Dim v = Item.Value.ToString.Replace(">", "").Replace("<", "").Replace("=", "").ToString
                    '    'If IsNumeric(v) Then
                    '    'trường hợp lớn hơn
                    '    If Item.Value.ToString.Contains(">") Then
                    '        Dim value = Item.Value.ToString.Replace(">", "")
                    '        If CDec(Me.GetFocusedRowCellValue(Me.FocusedColumn.FieldName)) > CDec(value) Then
                    '            e.ErrorText = Me.FocusedColumn.Caption & " " & "không được lớn hơn " & Format(CDec(value), "N0") & "!"
                    '            e.Valid = False
                    '            Exit Sub
                    '        End If
                    '    End If
                    '    'trường hợp nhỏ nhơn
                    '    If Item.Value.ToString.Contains("<") Then
                    '        Dim value = Item.Value.ToString.Replace("<", "")
                    '        If CDec(Me.GetFocusedRowCellValue(Me.FocusedColumn.FieldName)) < CDec(value) Then
                    '            e.ErrorText = Me.FocusedColumn.Caption & " " & "không được nhỏ hơn " & Format(CDec(value), "N0") & "!"
                    '            e.Valid = False
                    '            Exit Sub
                    '        End If
                    '    End If
                    '    'trường hợp bằng
                    '    If Item.Value.ToString.Contains("=") Then
                    '        Dim value = Item.Value.ToString.Replace("=", "")
                    '        If CDec(Me.GetFocusedRowCellValue(Me.FocusedColumn.FieldName)) = CDec(value) Then
                    '            e.ErrorText = Me.FocusedColumn.Caption & " " & "không được bằng " & Format(CDec(value), "N0") & "!"
                    '            e.Valid = False
                    '            Exit Sub
                    '        End If
                    '    End If
                    'Else
                    '    DevExpress.XtraEditors.XtraMessageBox.Show("coi lại bắt lỗi của " & Item.Value.ToString, "Thông báo lỗi lập trình", MessageBoxButtons.OK, MessageBoxIcon.Error)
                    '    Exit Sub
                    '    'End If
                    'End If

                    '=====================================
                    If Item.Value.ToString.ToLower = "not null" Then
                        If IsDBNull(e.Value) Or IsNothing(e.Value) Then
                            e.ErrorText = " không được rỗng !"
                            e.Valid = False
                            Exit Sub
                        ElseIf e.Value.ToString.Trim = "" Then
                            e.ErrorText = " không được rỗng !"
                            e.Valid = False
                            Exit Sub
                        End If
                    ElseIf Item.Value.ToString.ToLower = "not 0" Then
                        'kiểm tra trc bằng 0
                        If IsNumeric(e.Value) Then
                            If CDec(e.Value) = 0 Then
                                e.ErrorText = " không được bằng 0 !"
                                e.Valid = False
                                Exit Sub
                            End If
                        Else
                            e.ErrorText = " không phải dạng số !"
                            e.Valid = False
                            Exit Sub
                        End If
                    ElseIf Item.Value.ToString.ToLower = "not 0 and not null" Then
                        If IsDBNull(e.Value) Or IsNothing(e.Value) Then
                            e.ErrorText = " không được rỗng !"
                            e.Valid = False
                            Exit Sub
                        ElseIf e.Value.ToString.Trim = "" Then
                            e.ErrorText = " không được rỗng !"
                            e.Valid = False
                            Exit Sub
                        End If
                        If IsNumeric(e.Value) Then
                            If CDec(e.Value) = 0 Then
                                e.ErrorText = " không được bằng 0 !"
                                e.Valid = False
                                Exit Sub
                            End If
                        Else
                            e.ErrorText = " không phải dạng số !"
                            e.Valid = False
                            Exit Sub
                        End If
                    End If

                    'Exit For
                End If
            Next
        Next
    End Sub
    Public Sub setBatLoi(ByVal ht As Hashtable)
        Me.htBatLoi = ht
    End Sub
    ''' <summary>
    ''' chỉ định bắt lỗi
    ''' </summary>
    ''' <param name="key">tên cột</param>
    ''' <param name="value">kiểu bắt lỗi là gì</param>
    ''' <remarks></remarks>
    Public Sub setBatLoi(ByVal key As Object, ByVal value As Object)
        Me.htBatLoi.Add(key, value)
    End Sub
    ''' <summary>
    ''' set focus trên igridview cột đầu tiên dòng cuối cùng 
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub setFocusDongDauTien()
        Me.MoveLast()
        Me.Focus()
        Me.AddNewRow()
        Me.FocusedColumn = Me.VisibleColumns(0)
        Me.ShowEditor()
    End Sub
    ''' <summary>
    ''' cập nhật giá trị lên lưới trước khi update tableadapter
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub setUpdateData()
        Try
            Dim view As ColumnView = Me.GridControl.FocusedView
            view.CloseEditor()
            view.UpdateCurrentRow()
            view.PostEditor()
            'Me.CloseEditor()
        Catch ex As Exception
            MessageBox.Show("setUpdate" & ex.Message)
        End Try
    End Sub
    Protected Overrides Function CreateAutoFilterCriterion(ByVal column As DevExpress.XtraGrid.Columns.GridColumn, ByVal condition As DevExpress.XtraGrid.Columns.AutoFilterCondition, ByVal _value As Object, ByVal strVal As String) As DevExpress.Data.Filtering.CriteriaOperator
        If column.ColumnType Is GetType(DateTime) AndAlso strVal.Length > 0 Then
            Dim type As BinaryOperatorType = BinaryOperatorType.Equal
            Dim operand As String = String.Empty
            If strVal.Length > 1 Then
                operand = strVal.Substring(0, 2)
                If operand.Equals(">=") Then
                    type = BinaryOperatorType.GreaterOrEqual
                ElseIf operand.Equals("<=") Then
                    type = BinaryOperatorType.LessOrEqual
                End If
            End If
            If type = BinaryOperatorType.Equal Then
                operand = strVal.Substring(0, 1)
                If operand.Equals(">") Then
                    type = BinaryOperatorType.Greater
                ElseIf operand.Equals("<") Then
                    type = BinaryOperatorType.Less
                End If
            End If
            If type <> BinaryOperatorType.Equal Then

                Dim val As String = strVal.Replace(operand, String.Empty)
                Try
                    Dim dt As DateTime = DateTime.ParseExact(val, "d", column.RealColumnEdit.EditFormat.Format)
                    Return New BinaryOperator(column.FieldName, dt, type)
                Catch
                    Return Nothing
                End Try
            End If
        End If
        Return MyBase.CreateAutoFilterCriterion(column, condition, _value, strVal)
    End Function
    'Protected Overrides Function ConvertGridFilterToDataFilter(ByVal criteria As DevExpress.Data.Filtering.CriteriaOperator) As DevExpress.Data.Filtering.CriteriaOperator
    '    Dim op As CriteriaOperator = MyBase.ConvertGridFilterToDataFilter(criteria)
    '    If Object.Equals(op, Nothing) Then
    '        Return Nothing
    '    End If
    '    Return CriteriaOperator.Parse(String.Format("FullTextContains(Content, '{0}')", """"c & FindFilterText & """"c))
    'End Function

    'Public Sub Me_MouseDown(sender As Object, e As MouseEventArgs)
    '    Throw New NotImplementedException
    'End Sub


End Class
